#!/bin/bash
#########################################################################
# Title:         Let's Encrypt SSL Certificates Revoker                 #
# Author(s):     desimaniac                                             #
# URL:           https://github.com/cloudbox/cloudbox                   #
# Description:   Revoke SSL certificates for current domain.            #
# --                                                                    #
#         Part of the Cloudbox project: https://cloudbox.works          #
#########################################################################
#                   GNU General Public License v3.0                     #
#########################################################################


# Regular color(s)
NORMAL="\033[0;39m"
GREEN="\033[32m"

echo -e "
$GREEN
 ┌───────────────────────────────────────────────────────────────────────────────────┐
 │ Title:             Let's Encrypt SSL Certificates Revoker                         │
 │ Author(s):         desimaniac                                                     │
 │ URL:               https://github.com/cloudbox/cloudbox                           │
 │ Description:       Revoke SSL certificates for current domain.                    │
 ├───────────────────────────────────────────────────────────────────────────────────┤
 │                Part of the Cloudbox project: https://cloudbox.works               │
 ├───────────────────────────────────────────────────────────────────────────────────┤
 │                        GNU General Public License v3.0                            │
 └───────────────────────────────────────────────────────────────────────────────────┘
$NORMAL
"

domain={{ user.domain }}

cd /opt/nginx-proxy/certs

sudo docker stop $(docker ps -aq)

for i in *.${domain}.chain.pem;
  do
    base=${i%%??????????}
    sudo certbot revoke -n --cert-path ${base}/fullchain.pem --key-path ${base}/key.pem
done

sudo chown -R {{ user.name }}:{{ user.name }} /opt/nginx-proxy
